﻿myApp.controller("ForgetPasswordController", function ($scope, $http, $modal, modalService, $sce, ngTableParams, $filter) {

    $scope.submit = function () {
        if (!validation())
            return;
        url = 'api/User/userForgetPassword';
        
        $http.post(url, $scope.data)
             .success(function (result) {               
                 $scope.loader.loading = false;
                 $scope.info = "Your request has been submitted successfully. Please check your email.";
                 $scope.data.Name = null;
                 $scope.data.Email = null;

             })
             .error(function (result) {
                 console.log("Error");
                 console.log(result);
                 $scope.loader.loading = false;
                 $scope.error = "Your request cannot be submitted now. Please contact our office directly for us to serve you immediately.";
             })
             
        

    }

    function validation() {
        $scope.warning = [];

        if (!$scope.data.Name)
            $scope.warning.push({ msg: "Name must not be empty!" });
        if (!$scope.data.Email)
            $scope.warning.push({ msg: "Email must not be empty!" });
       
        if ($scope.warning.length > 0)
            return false;
        else {
            $scope.warning = null;
            return true;
        }
    }

})